<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增工器具使用记录')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-history-add">

            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">RFID：</label>
                    <div class="col-sm-8">
                        <input name="rfid" class="form-control" type="text" required>
                    </div>
                </div>
            </div>

            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">工器具类型：</label>
                    <div class="col-sm-8">
                        <select id = "toolTypeCode" name="toolTypeCode" class="form-control" th:with="type=${@dict.getType('tools_type')}" onchange = "changeToolType()" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">工器具名称：</label>
                    <div class="col-sm-8">
                        <select name="toolId" id="toolId" class="form-control"  required>
                        </select>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        window.onload = function() {
            changeToolType();
        };
        var prefix = ctx + "system/history"
        $("#form-history-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-history-add').serialize());
            }
        }

        function changeToolType() {
            var checkValue=$("#toolTypeCode").val();  //获取Select选择的Value
            // 获取select元素
            var select = document.getElementById('toolId');
            select.innerHTML = '';//清空

            $.ajax({
                type: "post",
                url: prefix + "/findDropDownList",
                data: {
                    "toolTypeCode": checkValue
                },
                success: function(data) {
                    // 动态添加选项
                    data.data.forEach(function(item) {
                        var option = document.createElement('option');
                        option.value = item.id;
                        option.text = item.toolName;
                        select.appendChild(option);
                    });
                }
            });
        }
    </script>
</body>
</html>